<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>增加激活码</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<link rel="stylesheet" href="layui/dist/formSelects-v4.css" />
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
	    <form class="layui-form">
	      <div class="layui-inline">
	        <label class="layui-form-label">金币</label>
	        <div class="layui-input-inline">
				<input class="layui-input" style="width:120px"type="number" name="Gold" id="Gold" value="0" autocomplete="off">
	        </div>
	      </div>
	      <div class="layui-inline">
	        <label class="layui-form-label">钻石</label>
	        <div class="layui-input-inline">
				<input class="layui-input" style="width:120px"type="number" name="Diamond" id="Diamond" value="0" autocomplete="off">
	        </div>
	      </div>
	      <div class="layui-inline">
	        <label class="layui-form-label">vip经验</label>
	        <div class="layui-input-inline">
				<input class="layui-input" style="width:120px"type="number" name="Vip" id="Vip" value="0" autocomplete="off">
	        </div>
	      </div>
	      <div class="layui-form-item">
	        <label class="layui-form-label">分组名称</label>
	        <div class="layui-input-block">
	          <input class="layui-input" style="width:120px" lay-verify="required" type="text" name="ActivationCodeName" id="ActivationCodeName" autocomplete="off">
	        </div>
	      </div>
	      
	      <div class="layui-form-item">
	        <label class="layui-form-label">设置数量</label>
	        <div class="layui-input-block">
	          <input type="number" style="width:200px" lay-verify="required" id="Count" name="Count"  autocomplete="off" class="layui-input" min="1">
	        </div>
	      </div>
	      <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit lay-filter="setState">立即提交</button>
              <button type="reset" style="width:120px"  class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
	  </form>
	
	
	    <script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script>
			layui.config({
		    	base:'layui/dist/'
		    }).extend({
		    	formSelects:'formSelects-v4'
		    });
		
		    layui.use(['layer','form','laydate','formSelects'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form,
		    	    laydate = layui.laydate,
		    	    formSelects = layui.formSelects;
		    	form.on('submit(setState)',function(obj){
		    		/* for(var i in obj.field) {
		    			if (i != "ActivationCodeName" && i != "Count") {
		    				if (obj.field[i] === '0') {
				    			layer.msg("道具数量不能为0",{icon:6});
				    			return false;
				    		}
		    			}
		    		} */
		    		if (parseInt(obj.field.Count) < 1) {
		    			layer.msg("生活激活码数量不能少于1",{icon:6});
		    			return false;
		    		}
		    		$.ajax({
	    				type:'POST',
	    				url:'activationCode/add',
	    				async:true,
	    				data:{formdata:JSON.stringify(obj.field),name:obj.field.ActivationCodeName,Count:obj.field.Count},
	    				success:function(resp){
	    					if(resp == "" || resp == null){
	    						layer.msg("设置成功",{icon:1});
	    						setTimeout(function (){
		    						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		                            parent.layer.close(index); //再执行关闭 
		                            parent.layer.closeAll();
								}, 1000);
	    						parent.layui.table.reload('AllTable',{});
	    					}else if(resp == "fail"){
	    						layer.msg("添加失败",{icon:2});
	    					}
	    				},error:function(){
	    					layer.msg("添加失败",{icon:2});
	    				}
	    			});
		    		return false;
		    	});
		    	
		    });
		</script>
    </body>
</html>